﻿<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Holidays
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="CurrentMenuIDContent" runat="server">configMenu</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
    <link rel="stylesheet" type="text/css" href="<%= Url.Content("~/Content/jquery-ui-1.8.16.custom.css") %>" />
    <script type="text/javascript" src="<%= Url.Content("~/Scripts/jquery-ui-1.8.16.custom.min.js") %>"></script>
    <script type="text/javascript" src="../../Scripts/site.js"></script>
    <script src="<%= Url.Content("~/Scripts/MicrosoftAjax.js") %>" type="text/javascript"></script>
    <script src="<%= Url.Content("~/Scripts/MicrosoftMvcAjax.js") %>" type="text/javascript"></script>
    <script src="<%= Url.Content("~/Scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
    <script type="text/javascript" src="../../Scripts/jquery.tablesorter.min.js"></script>
    <script type="text/javascript" src="../../Scripts/jquery.tablesorter.pager.js"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        Define New Holiday</h2>
    <br />
    <% Html.EnableClientValidation()%>
    <% Using (Ajax.BeginForm("SaveHoliday", New AjaxOptions With {.UpdateTargetId = "holidayContent", .OnBegin = "ajaxValidate", .OnSuccess = "clearFields"}))%>
    <div id="errors">
    </div>
    <table>
        <tr>
            <td width="200px">
                <div class="calendar-field">
                    <%= Html.TextBox("holidayDate", Nothing, New With {.class = "text"})%>
                </div>
            </td>
            <td align="right" width="350px">
                <%= Html.Hidden("currHolidayID", 0)%>
                <%= Html.TextBox("holidayDesc", Nothing, New With {.class = "text w-wide-input"})%>
            </td>
            <td align="left" width="50px">
                <input type="submit" class="button" value="   Save   " />
            </td>
            <td width="*">
                &nbsp;
            </td>
        </tr>
        <tr>
            <td colspan="2" id="holidayContent">
                <% Html.RenderPartial("~/Views/Configuration/Controls/HolidayList.ascx", ViewData("Holidays"))%>
            </td>
            <td colspan="2">
                &nbsp;
            </td>
        </tr>
    </table>
    <% End Using%>
    <% Html.RenderPartial("~/Views/History/Controls/History.ascx")%>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#holidayDate").datepicker({
                showOn: "button",
                buttonImage: '<%= Url.Content("~/Content/img/calendar.gif") %>',
                buttonImageOnly: true,
                dateFormat: 'dd-M-yy'
            });

        });

    function ajaxValidate() {
        return $('form').validate({
        rules: {
            "holidayDesc": { required: true },
            "holidayDate": { required: true }
        },
        messages: {
            "holidayDesc": "Please enter a description",
            "holidayDate": { required: "Please select a date" }
            },
            errorLabelContainer: '#errors',
            wrapper: 'li'
        }).form();
    }

    function setCurrentHoliday(id, desc,date) {
        $("#holidayDesc").val(desc);
        $("#currHolidayID").val(id);
        $("#holidayDate").val(date);
        clearSelection();
        $("#holRow_" + id).addClass("selected");
    }

    function clearFields(){
        $('#holidayDesc').val("");
        $("#currHolidayID").val(0);
    }

    function clearSelection() {
        $('#assetHolidayTable tbody tr').each(function (index) {
            $(this).removeClass("selected");
        });
    }

    function deleteWithEffect(id) {
        if (confirm("Do you really want to delete this holiday?")) {
            jQuery.ajax({
                type: 'POST',
                data: { id: id },
                url: '<%: Url.Action("DeleteHoliday") %>',
                dataType: "json",
                success: function (result) {
                    if (result.Result === "ok") {
                        $("#holRow_" + id + " td").effect("highlight",
                        { mode: "hide", color: "#ff4444" },
                        1000,
                        function () {
                            $(this).remove();
                            clearFields();
                        });
                    }
                    else {
                        alert(result.Message);
                    }
                }
            });
        }
    }

    </script>
</asp:Content>
